package com.simple.annotation.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ReflectUtil;
import com.simple.annotation.Config;
import com.simple.core.InstanceConfig;
import com.simple.manager.impl.InstanceManager;
import com.simple.tools.ReflectionsTool;

import java.util.Set;

public class ConfigImpl {

    public static void init() {
        Set<Class<?>> classes = ReflectionsTool.getAnnotationByClass(Config.class);
        if (CollUtil.isEmpty(classes)) {
            return;
        }
        for (Class<?> aClass : classes) {
            if (!InstanceConfig.class.isAssignableFrom(aClass)) {
                continue;
            }
            InstanceConfig object = (InstanceConfig) ReflectUtil.newInstance(aClass);
            object.config(InstanceManager.getInstance());
        }
    }
}
